package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsOrderLjService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsOrderLjForm;
import com.youlai.boot.system.model.query.LpsOrderLjQuery;
import com.youlai.boot.system.model.vo.LpsOrderLjVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 利居前端控制层
 *
 * @author lwb
 * @since 2025-07-18 14:53
 */
@Tag(name = "利居接口")
@RestController
@RequestMapping("/api/v1/lpsOrderLjs")
@RequiredArgsConstructor
public class LpsOrderLjController  {

    private final LpsOrderLjService lpsOrderLjService;

    @Operation(summary = "利居分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderLj:query')")
    public PageResult<LpsOrderLjVO> getLpsOrderLjPage(LpsOrderLjQuery queryParams ) {
        IPage<LpsOrderLjVO> result = lpsOrderLjService.getLpsOrderLjPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增利居")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsOrderLj:add')")
    public Result<Void> saveLpsOrderLj(@RequestBody @Valid LpsOrderLjForm formData ) {
        boolean result = lpsOrderLjService.saveLpsOrderLj(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取利居表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderLj:edit')")
    public Result<LpsOrderLjForm> getLpsOrderLjForm(
        @Parameter(description = "利居ID") @PathVariable Long id
    ) {
        LpsOrderLjForm formData = lpsOrderLjService.getLpsOrderLjFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改利居")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderLj:edit')")
    public Result<Void> updateLpsOrderLj(
            @Parameter(description = "利居ID") @PathVariable Long id,
            @RequestBody @Validated LpsOrderLjForm formData
    ) {
        boolean result = lpsOrderLjService.updateLpsOrderLj(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除利居")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderLj:delete')")
    public Result<Void> deleteLpsOrderLjs(
        @Parameter(description = "利居ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsOrderLjService.deleteLpsOrderLjs(ids);
        return Result.judge(result);
    }
}
